/*
* Copyright (C) 2013 Nivis LLC.
* Email:   opensource@nivis.com
* Website: http://www.nivis.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
* 
* Redistribution and use in source and binary forms must retain this
* copyright notice.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef __APPROUTESREPORTCMD_H_
#define __APPROUTESREPORTCMD_H_

#include <map>
#include <list>

#include <WHartHost/applicationcmds/AbstractAppCommand.h>
#include <WHartHost/database/DevicesManager.h>


namespace hart7 {
namespace hostapp {

class IAppCommandVisitor;
class AppRoutesReportCmd;

typedef boost::shared_ptr<AppRoutesReportCmd> AppRoutesReportCmdPtr;

class AppRoutesReportCmd: public AbstractAppCommand
{
public:
	enum RoutesReportState
	{
		GetRouteLists_State,
		GetSourceRoutes_State
	};

	typedef std::map<DevicePtr, std::list<int> > RouteIdsPerDevice;

public:
	AppRoutesReportCmd(int p_nNbOfNeededReports);
	virtual bool Accept(IAppCommandVisitor& visitor);

protected:
	void DumpToStream(std::ostream& p_rStream) const;

public:
	void RegisterRouteListReport();
	void RegisterSourceRouteReport();
	void RegisterRoute(DevicePtr& p_rDevice, int p_nRouteId);
	bool ReceivedAllRouteListReports();
	bool ReceivedAllSourceRouteReports();

public:
	RoutesListT& GetRoutes();
	SourceRoutesListT& GetSourceRoutes();


public:
	RoutesReportState m_enumState;
	RouteIdsPerDevice m_oRouteIdsPerDevice;

private:
	int m_nNbOfNeededRouteListReports;
	int m_nNbOfNeededSourceRoutesReports;

private:
	RoutesListT m_Routes;
	SourceRoutesListT m_SourceRoutes;
	int m_noOfDevices;

};

}
}

#endif //__APPROUTESREPORTCMD_H_

